import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

/* 解决：VUE项目Avoided redundant navigation to current location: “/XXX“.问题 */
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}


const Squre = () => import('../views/Squre.vue')
const Hit = () => import('../views/Hit.vue')
const Talk = () => import('../views/Talk.vue')
const userPage = () => import('../views/userPage.vue')
const MainPage = () => import('../views/MainPage.vue')
const Refresh = () => import('./refresh.vue')

const routes = [
    {
        path: '',
        redirect: '/mainPage'
    }, 
    {
        path: '/mainPage',
        component: MainPage, 
        redirect: '/squre',
        children: [
            {
                path: '/squre',
                component: Squre
            },
            {
                path: '/hit',
                component: Hit
            }, 
            {
                path: '/talk',
                component: Talk
            }, {
                path: '/refresh',
                component: Refresh
            }
        ]
    }, 
    {
        path: '/userPage',
        component: userPage
        
    }
]

const router = new VueRouter({
    routes, 
    mode: 'history'
})

export default router

